<template>
	<div class="allcontainer" v-loading="loading">
		<div class="h2">活动签到管理</div>
		<div class="bg-white">
			<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form"  :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="状态">
							<a-select :allowClear="true" @click="qingqiu" v-decorator="['type']" placeholder="请选择状态" optionFilterProp="children">
								<a-select-option v-for="(item, index) in TypeList" :key="index" :value="item.Key">{{ item.Value }}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="16" style="margin-top: 2px;">
						<a-button type="primary" html-type="submit">搜索</a-button>
						<a-button @click="handleReset">重置</a-button>
						<a-button type="primary" @click="addList" v-if="activeState!=5 && activeState!=4 && ChargeUserNo==UserInfo.UserNo && manageprogress!==3">新增</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div class="table">
			<el-table stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%">
				<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
				<el-table-column prop="TypeName" label="类型" min-width="120" align="center"></el-table-column>
				<!-- <el-table-column prop="IsManager" label="职责" min-width="50">
					<template slot-scope="scope">
						<a-tag color="pink" v-if="scope.row.IsManager == true">管理员</a-tag>
						<a-tag color="green" v-else>成员</a-tag>
					</template>
				</el-table-column> -->
				<el-table-column prop="SignNum" label="签到人数" min-width="100" align="right">
					<template slot-scope="scope">
						<div>
							已签到人数：
							<a-tag class="tagcursor" color="green" @click="SignNumDetail(scope.row)">{{ scope.row.SignNum }}</a-tag>
						</div>
						<div>
							未签到人数：
							<a-tag class="tagcursor" color="red" @click="NoSignNumDetail(scope.row)">{{ scope.row.NoSignNum }}</a-tag>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="AddTime" label="时间" min-width="100" align="center">
					<template slot-scope="scope">
						<div>始：{{ scope.row.StartTime }}</div>
						<div>终：{{ scope.row.EndTime }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="AddUserName" label="添加人" min-width="100" align="center">
					<template slot-scope="scope">
						{{ scope.row.AddUserName | testname }} / {{ scope.row.AddUserNo | testno }}
					</template>
				</el-table-column>
			<!-- 	<el-table-column prop="AddUserNo" label="编号" min-width="100">
					<template slot-scope="scope">
						{{ scope.row.AddUserNo | testno }}
					</template>
				</el-table-column> -->
				<el-table-column prop="IsEnable" label="操作" min-width="100" fixed="right">
					<template slot-scope="scope">
						<div class="user-btn user-btn-auto">
							<span class="modify" v-if="activeState!=5 && activeState!=4 && ChargeUserNo==UserInfo.UserNo && manageprogress!==3" @click="detail(scope.row)">修改</span>
							<span class="codeimg" v-if="activeState != 5 && activeState != 4 && moment().isBetween(scope.row.StartTime, scope.row.EndTime)" @click="codeimg(scope.row)">二维码</span>
							<span class="delete" v-if="activeState!=5 && activeState!=4 && ChargeUserNo==UserInfo.UserNo && manageprogress!==3" @click="deletemember(scope.row)">删除</span>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<!-- <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage"
			 :page-sizes="pagination.pageSizeOptions" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
			 :total="pagination.total"></el-pagination> -->
		</div>
		</div>
		<add :text="text" :ID="ID" v-show="addIf" @closeFun="closeFun"></add>
		<imgcode :codeID="codeID" :time="time" v-show="codeIf" @closeFun="closeFun"></imgcode>
		<detail :text="detailtext" v-show="detailIf" @closeFun="closeFun"></detail>
	</div>
</template>

<script>
import Func from '@/utils/func';
import Cache from '@/utils/cache';
import { UserActivitySignList, DeleteUserActivitySign, DoGetActivitySignTypeList, UserActivityDetail } from '@/api/follow';
import add from './AddActivitySign';
import imgcode from './QRcode';
import detail from './UserActivitySignDetail';
import moment from 'moment'
const data = [];
export default {
	components: {
		add,
		detail,
		imgcode
	},
	data() {
		return {
			data,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			addIf: false,
			text: {},
			detailtext: {},
			codeID: '',
			visible: false,
			confirmLoading: false,
			itemId: '',
			departmentList: [],
			worklist: [],
			loading: false,
			values: {},
			pages: {
				pageIndex: 1,
				pageSize: 20
			},
			tableHeight: parseFloat(window.innerHeight - 160),
			TypeIDList: [],
			DepartCodeList: [],
			ProjectIDList: [],
			ishaveid: true,
			selectList: {},
			showModal: false,
			UserInfo: Cache.get('myInfo'),
			ChairmanNo: this.$route.query.ChairmanNo,
			linktype: 1,
			ID: this.$route.query.ID,
			visible: false,
			deletelist: {},
			time: '',
			codeIf: false,
			detailIf: false,
			TypeList: [{
				Key:"1",
				Value:"签到"
			},
			{
				Key:"2",
				Value:"签退"
			}
			],
			activeState: this.$route.query.State,
			ChargeUserNo:'',
			manageprogress:this.$route.query.manageprogress
		};
	},
	computed: {},
	created() {
		 // this.GetTypeList()
		this.getList();
		this.getDetail();
	},
	mounted() {},
	methods: {
		moment,
		NoSignNumDetail(row) {
			this.$router.push({
				name: 'NoSignNumList',
				query: {
					ID: row.ID,
					State:this.activeState
				}
			});
		},
		SignNumDetail(row) {
			this.$router.push({
				name: 'SignNumList',
				query: {
					ID: row.ID
				}
			});
		},
		qingqiu() {
			this.GetTypeList();
		},
		codeimg(text) {
			// let data={}
			// data.id=text.ID
			// let res= await GetUserActivitySignQRImage(data)
			this.time = new Date();
			this.codeID = text.ID;
			this.codeIf = true;
		},
		handleCancel(e) {
			this.visible = false;
			this.getList();
		},
		deletemember(text) {
			// this.visible = true
			// this.deletelist = text
			let that = this;
			this.$confirm({
				title: '提示',
				content: `您确定删除此条记录吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await DeleteUserActivitySign(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		detail(text) {
			this.text = text;
			this.time = new Date();
			this.addIf = true;
		},
		look(text) {
			this.detailtext = text;
			this.time = new Date();
			this.detailIf = true;
		},
		handleChange(val) {
			this.currentRow = val;
			if (val.ID) {
				this.ishaveid = false;
				this.selectList = val;
			} else {
				this.ishaveid = true;
			}
		},
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				this.values = values;
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList() {
			this.loading = true;
			let data = {};
			if (this.values) {
				data = this.values;
			}
			data.activityID = this.$route.query.ID;
			// data.type=1
			data.pageIndex = this.pagination.currentPage;
			data.pageSize = this.pagination.pageSize;
			let res = await UserActivitySignList(data);
			this.loading = false;
			this.data = res.data.data;
		},
		async getDetail() {
			let res = await UserActivityDetail({ ID: this.$route.query.ID });
			// this.activeState = res.data.data.State;
			this.ChargeUserNo = res.data.data.ChargeUserNo
		},
		async GetTypeList() {
			let res = {};
			let data = {};
			res = await DoGetActivitySignTypeList(data);
			this.TypeList = res.data.data;
			
		},
		addList() {
			this.text = {};
			this.addIf = !this.addIf;
		},
		modifyList(text) {
			text = Object.assign(text, {
				time: new Date()
			});
			this.addIf = !this.addIf;
			this.text = text;
		},
		closeFun(index) {
			this.showModal = false;
			this.addIf = false;
			this.detailIf = false;
			this.codeIf = false;
			this.getList();
		}
	}
};
</script>

